﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bestlife.ERP.Entities;
using Bestlife.ERP.BusinessRules;

public partial class Store_Manager_SM_SAN_Approval : System.Web.UI.Page
{
     string proid;
    string stockid;
    string code;
    decimal quantity;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        string user = Session["username"].ToString();
        List<Bestlife.ERP.Entities.E_Stock_Adjustment> listgrn = new List<Bestlife.ERP.Entities.E_Stock_Adjustment>();
        Bestlife.ERP.Entities.E_Stock_Adjustment stock = new E_Stock_Adjustment();
        int i = ASPxGridView1.VisibleRowCount;
         Boolean result=false;
        List<Object> itemid1 = ASPxGridView1.GetSelectedFieldValues("Sto_ID");
        List<Object> itemid = ASPxGridView1.GetSelectedFieldValues("Pro_ID");
        List<Object> itemid2 = ASPxGridView1.GetSelectedFieldValues("Code");       
        List<Object> itemid4 = ASPxGridView1.GetSelectedFieldValues("Qty");
        int j = itemid.Count;




        if (itemid.Count == 0 || itemid1.Count == 0 || itemid2.Count == 0 || itemid4.Count == 0)
        {
            ASPxLabel4.Visible = true;
            ASPxLabel4.Text = "Please select order items ";
        }
        else
        {
            foreach (object selectitemid in itemid)
            {
                proid = selectitemid.ToString();

            }
            foreach (object selectitemid1 in itemid1)
            {
                stockid = selectitemid1.ToString();

            }
            foreach (object selectitemid2 in itemid2)
            {
                code = selectitemid2.ToString();

            }

            foreach (object selectitemid4 in itemid4)
            {
                quantity = decimal.Parse(selectitemid4.ToString());

            }
            for (int k = 0; k < itemid.Count; k++)
            {

                stock.Code = itemid2.ToString();
                stock.Proid = itemid.ToString();

                stock.Stoid = itemid1.ToString();
                listgrn.Add(stock);

            }
        }
                

        E_Stock_Adjustment stock1 = new E_Stock_Adjustment();
        stock1.SAid = DropDownList1.Text;
        string status = B_Stock_ADjustment.getstatus(DropDownList1.Text);
      string branch = B_Stock_ADjustment.getbranch(DropDownList1.Text);
      stock1.Status = status;

      //Bestlife.ERP.DataAccess.D_Stock_Adjustment.getAllproduct(stock.SAid); 
      
      if (status == "Minus" && branch=="Kandy")
      {
          Bestlife.ERP.BusinessRules.B_Stock_ADjustment.stockadjustmentminusKandy(stock, user);
      }
      if (status == "Add       " && branch == "Kandy")
      {
          Bestlife.ERP.BusinessRules.B_Stock_ADjustment.stockadjustmentaddKandy(stock, user);
      }
      if (status == "Minus" && branch == "Pandura")
      {
          Bestlife.ERP.BusinessRules.B_Stock_ADjustment.stockadjustmentminusPanadura(stock, user);
      }
      if (status == "Add       " && branch == "Pandura")
      {
          Bestlife.ERP.BusinessRules.B_Stock_ADjustment.stockadjustmentaddPanadura(stock, user);
      }
        
    }
}